package com.clear.honghefinance.common.enums;

import lombok.Getter;

@Getter
public enum ApiResponseCodeEnum {

    /**
     * 成功
     */
    SUCCESS(0, "success"),

    /**
     * 参数错误
     */
    PARAMETER_INVALID(100, "parameter_invalid"),


    /**
     * 业务错误
     */
    BUSINESS_ERROR(200, "业务错误"),

    /**
     * 登录错误
     */
    LOGIN_ERROR(201, "登录失败"),

    /**
     * 账号或密码错误
     */
    ACCOUNT_PASSWORD_ERROR(202, "账号或密码错误"),

    /**
     * 账号错误
     */
    ACCOUNT_ERROR(203, "账号错误"),

    /**
     * 服务异常
     */
    SERVICE_ERROR(500, "service_error");

    private final Integer code;
    private final String message;

    ApiResponseCodeEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public static ApiResponseCodeEnum getByCode(int codeVal) {
        for (ApiResponseCodeEnum apiResponseCodeEnum : ApiResponseCodeEnum.values()) {
            if (apiResponseCodeEnum.code == codeVal) {
                return apiResponseCodeEnum;
            }
        }
        return null;
    }
}